All Questions
Tagged with stringshell-script
170 questions
-1votes
2answers
60views
Split string with 0-2 / (or determine there's none) (Bash)
Update: Up to 2 "/" in the string. String structure is either: Character set name/LF Character set name/CRLF Character set name/CRLF/(unknown purpose, likely a number) Character set name ...
2votes
1answer
148views
How to check what character a variable contains and compare it with a number? [closed]
I have an hour record in which subsequent hours are written from 1 to 9 as numbers and then as subsequent alphabetic characters. I would like to save the time in a normal format, so I need to convert ...
1vote
1answer
267views
How to convert all newlines to "\n" in POSIX sh strings
I have a string that contains newline characters. I want to escape all newlines in that string by replacing all newline characters with a string of two characters: "\n". How can I do this in ...
0votes
1answer
184views
Error in chaining multiple conditions inside a single if statement
I am working on a shell script and a part of the script should check if a file doesn't exist or if the filename provided is null (i.e. no filename has been provided). Here is my code - if ! [[ -e &...
0votes
4answers
216views
How to remove the superfluous "./" from a path?
Consider the following script compare_times.sh (thx to http://superuser.com/a/1780500): #!/bin/bash # Syntax: compare_times.sh directory_1 directory_2 # Semantics: for pairs of files with the same ...
0votes
0answers
36views
Comparing a text file's unique content to expected string not registered as equal
I wrote a shell script to check which ".err" text files are empty. Some files have a specific repeated phrase, like this example file fake_error.err (blank lines intentional): WARNING: ...
0votes
0answers
78views
Creating a script which compares the return value from an AT command
I am trying to write a shell script that can save the output of a piped process to a variable. This variable is then compared to a known string in order to discern whether or not my AT modem is ...
1vote
3answers
108views
get specific output in linux after string
Controller loading lists... ------------------------------------------------- command: select SERVICE_NAME from <table_name> ------------------------------------------------- ...
0votes
0answers
17views
How to returns the correct character after manipulating the output of ps ax | grep [duplicate]
I would like to have some help writing a script (which should works on freebsd where I have sh as default) that should grab a precise character when I do a "ps ax | grep" command from the ...
2votes
3answers
272views
Why do I need eval in this example?
I'm exploring the notion of having a shell script input and output two dimensional structures of strings, with the limitation that the strings do not contain newlines. They can contain spaces. The way ...
1vote
1answer
208views
IP address string manipulation problem
I am trying to build three octets 10.AB.C9 from a 5 digit number: 12ABC: 12 = first octet AB = Second octet C = Third octet There are two scenarios with my existing code that can cause an in correct ...
0votes
3answers
166views
Better way to convert IP?
I am trying to convert 10.AB.C9.XYZ to 10.AB.C2.252. Right now I am extracting each character and piecing them together. ip_main=10.AB.C9.XYZ A_char=${ip_main:3:1} B_char=${ip_main:4:1} C_char=${...
0votes
1answer
58views
String compare negating in bash doesn't behave as it should be?
I have this little bash script: readonly imagick_extension=$(cat "${php_configuration_file}" | grep imagick) echo "Imagick extension grep value: $imagick_extension" if [ "${...
1vote
3answers
576views
Encapsulate only comma-separated strings in quotes
I have some data that is currently in TSV format, but needs to be converted into CSV format. The only problem is that occasionally in the TSV, there are some values that include commas that are not ...
1vote
3answers
7kviews
if-statement with ((...)) string comparison not working in a bash script
I have written below script: #!/usr/bin/bash STR_1="nfosys" STR_2="Infosys" if (( $STR_1 == $STR_2 )) then echo "Strings are equal" else echo "...